package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.AccountCoupons;
import com.fantastic.model.pojo.zjs.AccountMember;
import com.fantastic.service.zjs.AccountCouponsService;
import com.fantastic.service.zjs.AccountMemberService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/6/4 20:38
 * @description: 账号和会员卡关联信息请求控制器
 */
@RestController
@RequestMapping("/accountMember")
public class AccountMemberControllerAdmin {
    @Resource
    private AccountMemberService accountMemberService;

    /**
     * 查询账号和会员卡关联信息
     *
     * @param accountMember
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/listAccountMember")
    public ResultData listAccountMember(AccountMember accountMember, @RequestParam(name="page",
            defaultValue = "1") int pageNum,
                                        @RequestParam(name="limit",defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<AccountMember> list = accountMemberService.listAccountMember(accountMember);
        PageInfo<AccountMember> PageInfo = new PageInfo<>(list);
        return new ResultData(RespStatusInfo.OK, PageInfo);
    }

    /**
     * 查询单个的账号和会员卡关联信息
     *
     * @param accountId
     * @param memberId
     * @return
     */
    @GetMapping("/getAccountMember")
    public ResultData getAccountMember(Integer accountId, Integer memberId) {
        return new ResultData(RespStatusInfo.OK, accountMemberService.getAccountMember(accountId, memberId));
    }

    /**
     * 添加账号和会员卡关联信息
     *
     * @param accountMember
     * @return
     */
    @PostMapping("/insertAccountMember")
    public ResultData insertAccountMember(AccountMember accountMember) {
        return new ResultData(RespStatusInfo.OK, accountMemberService.insertAccountMember(accountMember));
    }

    /**
     * 修改账号和会员卡关联信息
     *
     * @param accountMember
     * @return
     */
    @PostMapping("/updateAccountMember")
    public ResultData updateAccountMember(AccountMember accountMember) {
        return new ResultData(RespStatusInfo.OK, accountMemberService.updateAccountMember(accountMember));
    }


    /**
     * 删除账号和会员卡关联信息
     *
     * @param accountId
     * @param memberId
     * @return
     */
    @PostMapping("/deleteAccountMember")
    public ResultData deleteAccountMember(Integer accountId, Integer memberId) {
        return new ResultData(RespStatusInfo.OK, accountMemberService.deleteAccountMember(accountId, memberId));
    }

}
